package com.example.front.arrange;

import com.example.front.arrange.AbstractRootTask;
import com.example.front.arrange.AbstractTask;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public abstract class Context {

    private AbstractRootTask abstractRootTask;
    private List<AbstractTask<?>> subTaskList = new ArrayList<>();

    private boolean allSuccess;

    public boolean getAllSuccess() {
        return allSuccess;
    }
    void setAllSuccess(boolean allSuccess) {
        this.allSuccess = allSuccess;
    }

    void setTaskList(Collection<AbstractTask<?>> subTaskList) {
        this.subTaskList.addAll(subTaskList);
    }

    public <T> T getResult(Class<? extends AbstractTask<T>> subTaskClass) {
        for (AbstractTask<?> subTask : subTaskList) {
            if (subTask.getClass() == subTaskClass) {
                return (T) subTask.getResult();
            }
        }
        return null;
    }
}
